package com.lyx.moocmusic.login.manager;


import com.lyx.moocmusic.model.user.User;

public class UserManager {

    private UserManager() {
    }

    private volatile static UserManager instance;

    private User mUser;

    public static UserManager getInstance() {
        if (instance == null) {
            synchronized (UserManager.class) {
                if (instance == null) {
                    instance = new UserManager();
                }
            }
        }
        return instance;
    }

    public boolean hasLogin() {
        return mUser != null;
    }

    public void saveUser(User user) {
        this.mUser = user;
        saveLocal(user);
    }

    private void saveLocal(User user) {

    }

    public User getUser() {
        if (mUser == null) {
            return getLocal();
        } else {
            return mUser;
        }
    }

    private User getLocal() {
        //todo
        return null;
    }

    public void removeUser() {
        mUser = null;
        removeLocalUser();
    }

    private void removeLocalUser() {
        //todo
    }

}
